package com.zhuiyun.project.api.article.controller;

import com.zhuiyun.project.api.article.entity.Article;
import com.zhuiyun.project.api.article.model.ArticleModel;
import com.zhuiyun.project.api.article.service.PublishArticleService;
import com.zhuiyun.project.api.filemanage.entity.FileManage;
import com.zhuiyun.project.api.filemanage.service.FileManageService;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName PublishArticleController
 * @Description TODO 文章发布
 * @Author maomao
 * @Date 2023/6/5 16:02
 **/
@CrossOrigin
@RestController
@RequestMapping("/publishArticle")
@Api(tags = "文章发布模块")
@Slf4j
public class PublishArticleController extends BaseController {

    @Autowired
    PublishArticleService publishArticleService;

    /**
     * @Author mao
     * @Description 医师文章发布 图片/视频 文章内容
     * @Date 2023/6/14 21:26
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param
     * @param
     */
    @PostMapping("/publishArticle")
    public String savePublishArticle(MultipartFile file, FileManage fileManage) throws CommonException {
        // test
        if (file!=null){
            // 调用发布文章服务的savePublishArticle方法，保存发布的文章
            return publishArticleService.savePublishArticle(file,fileManage);
        }else {
            return null;
        }
    }
    /**
     * @Author mao
     * @Description 医师文章发布 图片/视频 文章内容
     * @Date 2023/6/14 21:26
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param
     * @param
     */
    @PostMapping("/publishArticle1")
    public CommonResult savePublishArticle1(MultipartFile file, FileManage fileManage) throws CommonException {
        // test
        if (file!=null){
            // 调用发布文章服务的savePublishArticle方法，保存发布的文章
            return CommonResult.ok(publishArticleService.savePublishArticle(file,fileManage)) ;
        }else {
            return null;
        }
    }
    /**
     * @Author ys
     * @Description 医师文章发布 图片/视频 文章内容
     * @Date 2023/6/14 21:26
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param
     * @param
     */
    @PostMapping("/insertPublishArticle")
    public CommonResult insertPublishArticle(@RequestBody Article article){
        return publishArticleService.insertPublishArticle(article);
    }
    /**
     * @Author ys
     * @Description 医师文章发布 图片/视频 文章内容
     * @Date 2023/6/14 21:26
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param
     * @param
     */
    @PostMapping("/insertPublishArticle1")
    public CommonResult insertPublishArticle1( Article article){
        return publishArticleService.insertPublishArticle(article);
    }
}
